<?php

class ShopModel extends Model {
	
	public function get_primary_key() {
		return $this->primary_key = 'id';
	}
	public function get_paisong_list(){
		
	}

	

	public function get_all_list($where,$order,$limit,$if_count=false){
		if($if_count){
		 $sql = "select count(c.id) as total from ".$this->prefix."content_1 c "."
				 left join ".$this->prefix."content_1_shop s on c.id=s.id "."
				 where $where";
				 $res = $this->db->query($sql)->row_array();
				 return $res['total'];
		   }
		  	 $sql = "select c.*,s.*,s.id as sid from ".$this->prefix."content_1 c "."
			 	 left join ".$this->prefix."content_1_shop s on c.id=s.id "."
				 where $where order by $order limit $limit";
		return $this->db->query($sql)->result_array();
	}
	
	public function get_one_list($id){
		if($id){
			$sql = "select c.*,s.*,s.id as sid from ".$this->prefix."content_1 c "."
			 	 left join ".$this->prefix."content_1_shop s on c.id=s.id "."
				 where c.id=$id";
			return $this->db->query($sql)->row_array();
		}
	}
	
	public function get_lirunjj($id,$xjxf){
			$xjxf = $xjxf/100;
			$sql = "select profit from ".$this->prefix."content_1 "."
				 where id=$id";
			$res = $this->db->query($sql)->row_array();
			$jine = $res['profit']*$xjxf;
			return $jine;
	}
	
	
	public function updatexiaoliang($id,$num){
		$sql = "update ".$this->prefix."content_1 set xiaoliang=xiaoliang+$num where id=$id";
		$this->db->query($sql);
	}

    public function get_cate($typeid=1){
            $sql = "select c.*,s.*,s.id as sid from ".$this->prefix."content_1 c "."
			 	 left join ".$this->prefix."content_1_shop s on c.id=s.id where s.tuijianleixing = $typeid limit 0,3"."
				 ";
            return $this->db->query($sql)->result_array();
    }

    public function get_comment($id,$where){
        $sql = "select c.*,m.name,m.logo from ".$this->prefix."shop_comment as c
         left join ".$this->prefix."member as m on c.member_id = m.id where $where and pingjia_id=$id";
        return $this->db->query($sql)->result_array();
    }

    public function get_zan($id){
        $sql = "select count(id) as total from ".$this->prefix."shop_comment where pingjia_id=$id and zan=1";
        return $this->db->query($sql)->result_array();
    }

    public function get_jifen($id){
        $sql = "select huodejifen from ".$this->prefix."content_1_shop where id=$id";
        return $this->db->query($sql)->row_array();
    }

    public function add_comment($id, $data) {
        if ($id) {
            $this->db->update('shop_comment', $data,array('id'=>$id));
            return $id;
        }
        $return = $this->db->insert('shop_comment', $data);
        if ($return) return $return;
        return false;
    }


	
	
	
	
	
	
	
	
	
	
	
	
	
	


}